/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package progweb.project.Manager;

import com.mysql.jdbc.Connection;

/**
 *
 * @author davide.bonomelli.1
 */
public class MyConnection implements Comparable {
    private Connection c;
    private boolean isFree;
    
    public MyConnection(){
        this.c = null;
        this.isFree = false;
    }
    
    public MyConnection(Connection existingConn){
        this.c = existingConn;
        this.isFree = true;
    }
    
    public Connection getConnection(){
        this.isFree=false;
        return this.c;
    }
    public boolean isFree(){
        return this.isFree;
    }

    public void setConnection(Connection newConn){
        this.c=newConn;
    }

    
    @Override
    public boolean equals(Object o){
        if(this.c.equals(((MyConnection)o).c) && this.isFree==((MyConnection)o).isFree)
            return true;
        return false;
    }
    
    @Override
    public int compareTo(Object o) {
        if(this.equals(((MyConnection)o)))
            return 0;
        else if(this.isFree == true && ((MyConnection)o).isFree == false)
            return -1;
        else
            return 1;
    }
    
    
}
